package com.wk.springboot.config;

import com.wk.springboot.dao.MyBatchDao;
import com.wk.springboot.taskletStep.FileDeletingTasklet;
import org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;

/**
 * @Classname BeanConfig
 * @Description 构建一些bean
 * @Date 2020/3/31 14:51
 * @Author by weikai
 */
@Configuration
public class BeanConfig {

  @Autowired
  MyBatchDao myBatchDao;

  @Bean
  public MethodInvokingTaskletAdapter methodInvokingTaskletAdapter(){
    MethodInvokingTaskletAdapter adapter = new MethodInvokingTaskletAdapter();

    adapter.setTargetObject(myBatchDao);
    adapter.setTargetMethod("updateFlag");

    return adapter;
  }

  /**
   * 这个taskletStep执行后会删除target\\tmp下的文件
   * @return
   */
  @Bean
  public FileDeletingTasklet fileDeletingTasklet() {
    FileDeletingTasklet tasklet = new FileDeletingTasklet();
    tasklet.setDirectoryResource(new FileSystemResource("target\\tmp"));
    return tasklet;
  }

}
